package Operation;
import Book.*;
import java.util.Scanner;

public class addBookOperate implements IOOperation{

    @Override
    public void work(Bookshelf bookshelf) {
        Scanner s = new Scanner(System.in);

        System.out.println("新增图书........");
        System.out.println("请输入书名：");
        String name = s.nextLine();
        Book[] books = bookshelf.getBookList();
        //判断图书已满吗？
        if(bookshelf.getUsedSize()==bookshelf.getBookList().length) {
            System.out.println("馆里图书已满，不能新增图书！");
            return;
        }

        //判断书名是否已经存在
        for (int i = 0; i < bookshelf.getUsedSize(); i++) {
            if(name.equals(books[i].getName())) {
                System.out.println("图书管已存在"+"《"+name+"》"+"，新增失败！");
                return;
            }
        }
        //不存在，即可新增！
        System.out.println("请输入输入作者：");
        String author = s.nextLine();
        System.out.println("请输入输入价格：");
        double price = s.nextDouble();
        System.out.println("请输入输入书的类型：");
        s.nextLine();
        String type = s.nextLine();
        Book book = new Book(name,author,price,type);
        bookshelf.setBook(book);
        bookshelf.setUsedSize(bookshelf.getUsedSize()+1);
        System.out.println("新增图书"+name+"成功！");


    }
}
